<template>

    <div @click="link({name:'orderDetail', params: {id: order.orderSn}})">
      <div class="p-header" >
        <div class="p-shop">
          <div class="p-pic" v-lazy:background-image="'http://www.gogagoga.cc/picfile/'+order.wPic">
          </div>
          <div class="p-name">{{order.wName}}</div>
          <icon symbol="right"> </icon>
        </div>
        <div class="p-state">
          <span v-if="order.oState == 0" class="text-def">未付款</span>
          <span v-if="order.oState == 1" class="text-def">待发货</span>
          <span v-if="order.oState == 2" class="text-def">待收货</span>
          <span v-if="order.oState == 3" class="text-def">待评价</span>
          <span v-if="order.oState == 4" class="text-def">已取消</span>
          <span v-if="order.oState == 6" class="text-def">已完成</span>
        </div>
      </div>
      <div class="p-goods">
        <span>{{order.goods}}</span>等商品
      </div>
      <div class="p-price">
        ¥{{order.oMoney}}
      </div>
      <div class="p-bottom">
        <a v-if="order.oState != 0" @click.stop href="tel:4001681520" class="o-btn" >售后服务</a>
        <a v-if="order.oState == 0" class="o-btn" @click.stop.prevent="cancelOrder(order.orderSn)">取消订单</a>
        <a  v-if="order.oState == 2" @click.stop.prevent="confirm(order.orderSn)">确认送达</a>
        <a v-if="order.oState == 0" class="o-btn yellow" @click.stop.prevent="link({name:'pay',params:{orderId:order.orderSn}})">前往支付</a>
        <a v-if="order.oState == 3" @click.stop.prevent="link({name:'rate',params:{id:order.orderSn}})">立即评价</a>
      </div>
    </div>

</template>
<script lang="babel">
  import api from '@api'
  import Vue from 'vue'
  import Icon from '@components/icon'
  export default{
    components: {
      Icon
    },
    props: ['order'],
    methods: {
      link(route) {
        this.$router.push(route)
      },
      async confirm(orderID) {
        if (confirm('确认收货？')) {
          let {data: {StatusCode}} = await api.get('api/v1/Order/confirmDelOrder.ashx', {orderSn: orderID});
          if (StatusCode === '200') {
            Vue.set(this.order, 'oState', 3)
            fetchOrderList(this.$store, 1);
            this.$store.dispatch('global/toast', '及时评价订单有积分赠送哦');
          }
        }
      },
      async cancelOrder (orderID) {
        if (confirm('确认删除？')) {
          let {data: {StatusCode, Status}} = await api.get('api/v1/Order/closeOrder.ashx', {orderSn: orderID});
          if (StatusCode === '200') {
            Vue.set(this.order, 'oState', 4)
            this.$store.dispatch('global/toast', '订单取消成功');

          } else {
            this.$store.dispatch('global/toast', Status);
          }
        }
      }
    }
  }
</script>